import 'package:flutter/material.dart';
import 'package:get/get.dart';

/// todo：通用顶部导航
/// AppBar仅能用于PreferredSizeWidget类型的场景 如：Scaffold 的 appBar
appBarWidget({
  String? title,
  bool? centerTitle,
  List<Widget>? actions,
  double? elevation,
  Widget? leading,
  double? titleSize,
  Color? backgroundColor,
  Color? leftColor,
  Color? titleColor,
}) {
  return AppBar(
    leading: leading ??
        InkWell(
          child: Icon(
            Icons.chevron_left,
            color: leftColor,
            size: 30,
          ),
          onTap: () => Get.back(),
        ),
    title: Text(
      title ?? '',
      style: TextStyle(
        fontSize: titleSize ?? 16,
        color: titleColor ?? Colors.black,
      ),
    ),
    centerTitle: centerTitle ?? true,
    actions: actions,
    elevation: elevation ?? 0.5,
    backgroundColor: backgroundColor,
  );
}

/// todo：可用于任意场景的顶部导航
appBarRowWidget({
  double? width,
  double? height,
  Widget? left,
  Widget? right,
  double? titleSize,
  String? title,
  double? rightWidth,
  double? leftWidth,
  Color? titleColor,
  Color? backgroundColor,
  Color? leftColor,
}) {
  return SafeArea(
    child: Container(
      width: width ?? Get.width,
      height: height ?? 45,
      color: backgroundColor ?? Colors.white,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Container(
            width: leftWidth ?? Get.width * 0.2,
            alignment: Alignment.centerLeft,
            child: left ?? InkWell(
                  child: Icon(
                    Icons.chevron_left,
                    size: 30,
                    color: leftColor ?? Colors.transparent,
                  ),
                  onTap: () {
                    Get.back();
                  },
                ),
          ),
          Expanded(child: Center(
            child: Text(
              title ?? '',
              style: TextStyle(
                fontWeight: FontWeight.w500,
                fontSize: titleSize ?? 16,
                color: titleColor,
              ),
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
            ),
          ),),
          Container(
            width: rightWidth ?? Get.width * 0.2,
            alignment: Alignment.centerRight,
            child: right,
          ),
        ],
      ),
    ),
  );
}
